/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boundary;

import entities.Recept;
import entities.Uzivatel;
import exceptions.ReceptNotFoundException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author tereza
 */
@Stateless
public class ReceptFacade extends AbstractFacade<Recept> implements IReceptFacade{
    @PersistenceContext(unitName = "SimpleEE6AppPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ReceptFacade() {
        super(Recept.class);
    }
    
    /**
     * Vrátí instanci Receptu podle nazvu, jinak vyhodi ReceptNotFoundException
     * @param nazev
     * @return Recept
     * @throws ReceptNotFoundException
     */
    public Recept kontrolaExistujicihoNazvu(String nazev) throws ReceptNotFoundException {
       Recept nalezen =(Recept)em.createQuery("SELECT u FROM RECEPT u WHERE u.NAZEV = :nazev") 
                .setParameter("nazev", nazev)
                .getSingleResult();
       if(nalezen == null){
           throw new ReceptNotFoundException();
       }
       else{
           return nalezen;
       }
    }
    
}